Learn R Programming

VeryLargeIntegers (version 0.1.8)

20. Next prime number: Next Prime Number

Description

The function nextprime computes and returns the smallest prime number that is greater than the given number.

Usage

nextprime(n, iter = 10, test = "MR")

# S3 method for default nextprime(n, iter = 10, test = "MR")

# S3 method for numeric nextprime(n, iter = 10, test = "MR")

# S3 method for vli nextprime(n, iter = 10, test = "MR")

Value

object of class vli

Arguments

n

object of class vli or 32 bits integer

iter

number of iterations for testing whether or not each number is prime; numeric

test

chosen test: "F" for the Fermat Test, "SS" for the Solovay-Strassen Test or "MR" (by default) for the Miller-Rabin Test; character

Author

Javier Leiva Cuadrado

Details

The number of iterations is configurable to set the desired accuracy. A small number of iterations might cause not finding a prime number.

Examples

Run this code
n <- as.vli("982234568923564")
x <- nextprime(n)
x
is.prime(x)

Run the code above in your browser using DataLab